<?php

/**
 * Created by phpstorem.
 * User: yangakw@qq.com
 * Sign: 猥琐发育，别浪
 * Date: 2018-06-23
 * Time: 上午 9:59
 */
class Articleaccount extends CI_Model
{
    public function by_id($id)
    {
        return $this->db->from('article_account')->where("id",$id)->get()->row();
    }
    public function by_user_id($user_id)
    {
        return $this->db->from('article_account')->where("user_id",$user_id)->get()->result();
    }
    public function by_article_user_id($aid,$user_id)
    {
        return $this->db->from('article_account')->where("user_id",$user_id)->where("article_id",$aid)->get()->row();
    }
    function add_view($aid,$uid){
        $data = $this->by_article_user_id($aid,$uid);
        if(empty($data)){
            $pv = 1;
            $this->db->insert("article_account",[
                "user_id"=>$uid,
                "article_id"=>$aid,
                "pv"=>$pv,
                "uv"=>1,
            ]);
        }else{
            $pv = $data->pv+1;
            $this->db->where("user_id",$uid)->where("article_id",$aid)->update("article_account",[
                "pv"=>$pv,
            ]);
        }

        return $pv;


    }
}